package com.gin.kotlin.no_gay_alliance.adapter.item

import android.content.Context
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.gin.kotlin.no_gay_alliance.R
import com.gin.kotlin.no_gay_alliance.base.GlideModule.Companion.CROSS_FADE
import com.gin.kotlin.no_gay_alliance.base.MyHandler
import com.gin.kotlin.no_gay_alliance.databinding.ItemItemLinearBinding
import com.gin.nga.response.item.ItemInfo
import com.gin.nga.response.item.TradeBit

class ItemLinerAdapter(context: Context, handler: MyHandler, listener: View.OnClickListener)
    : AbstractItemAdapter<ItemItemLinearBinding>(context, handler, true,listener ) {
    override fun onBindViewHolder(holder: ViewHolder<ItemItemLinearBinding>, position: Int, b: ItemItemLinearBinding, dataModel: ItemInfo) {
        super.onBindViewHolder(holder, position, b, dataModel)
        // 图标
        Glide.with(context)
            .load(dataModel.getUrl())
            .error(R.drawable.ic_gift)
//            .placeholder(R.drawable.ic_gift)
            .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE))
            .into(b.ivItemInfo)

        b.tvItemName.text = dataModel.typeInfo?.name
        b.tvItemDescription.text = dataModel.typeInfo?.description
        b.tvCount.text = "x${dataModel.count}"
        b.tvItemPermissionToBuy.text = dataModel.typeInfo?.permissionToBuy?.let { "要求: $it" }
        // 价格
        when (dataModel.tradeBit){
            TradeBit.COPPER -> b.tvPrice.text = context.getString(R.string.item_price_copper, dataModel.price.toString())
            TradeBit.N_COIN -> b.tvPrice.text = context.getString(R.string.item_price_n_coin, dataModel.price.toString())
            else->{}
        }
    }
}